﻿using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Navigation;

using Microsoft.Phone.Controls;

using Microsoft.Phone.Shell;

using System.IO.IsolatedStorage;

using System.Windows.Media;

using Eventhere.Work;




namespace Eventhere.Events
{

    public partial class EventHome : PhoneApplicationPage
    {

        private List<Event> events;

        private User user;




        public EventHome()
        {

            InitializeComponent();

            if (this.events != null)

                this.events.Clear();

            expander1.Items.Clear();

            expander2.Items.Clear();




            if (IsolatedStorageSettings.ApplicationSettings.Contains("Events"))

                this.events = (List<Event>)IsolatedStorageSettings.ApplicationSettings["Events"];




            if (IsolatedStorageSettings.ApplicationSettings.Contains("User"))

                this.user = (User)IsolatedStorageSettings.ApplicationSettings["User"];




            Visibility darkBackgroundVisibility = (Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"];




            foreach (Event e in events)
            {

                Button b = new Button();

                b.Content = e.NameEvent;

                b.Background = new SolidColorBrush(Color.FromArgb(255, 60, 60, 60));

                b.BorderBrush = new SolidColorBrush(Colors.Black);

                b.FontSize = 24;

                b.FontWeight = FontWeights.Light;

                b.Margin = new Thickness(-13.5);

                if (e.MailAuthorEvent == user.MailContact)

                    expander1.Items.Add(b);

                else

                    expander2.Items.Add(b);




                b.Click += new RoutedEventHandler(button_click);

            }







        }




        private void button_click(object sender, RoutedEventArgs e)
        {

            if (((expander1.IsExpanded == true) && expander1.Items.Contains(((Button)sender))) || ((expander2.IsExpanded == true) && expander2.Items.Contains(((Button)sender))))

                NavigationService.Navigate(new Uri("/Events/EventDetails.xaml", UriKind.RelativeOrAbsolute));

        }







        private void btParticipation_Click(object sender, RoutedEventArgs e)
        {

            throw new NotImplementedException();

        }

    }

}